<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@include file="/WEB-INF/views/include/weixinhead.jsp" %>
</head>
<body>
<div data-role="page" class="page">
        <div data-role="header" class="header header-1">修改手机号码
            <span><a href="/f/campusinfo/personMsg1" data-transition="slideup" data-ajax="false"><span>取消</span></a></span>
        </div>
    <div role="main" class="content">
        <div class="account border-2">
            <div class="register-left">手机</div>
            <div class="register-right"><input type="text" class="non-empty no-space positive-integer" id="studentTel" placeholder="输入手机号"></div>
            <div class="register-tip" style="width:132px"></div>
        </div>
        <div class="account border-2">
            <div class="register-left">验证码</div>
            <div class="register-right"><input type="text" class="non-empty" id="verificationCode" placeholder="验证码" class="verifyCodeSend">
                <div class="verifyCodeSend-div notActive" id="verifyCodeSend-div">获取验证码</div>
            </div>
        </div>
        <div class="tip"></div>
        <button id="alterPhoneNo-btn" class="notActive">确定修改</button>
    </div>
</div>
<script>
    var mobileTOF=false;
    /*验证手机号码格式*/
    $("#studentTel").blur(function () {
        var tel=$("#studentTel").val()
        if(tel!= ""){
            if (!$("#studentTel").val().match(/^[1]\d{10}$/)) {
                $(".register-tip").eq(0).html("号码格式不正确");
                $("#verifyCodeSend-div").addClass("notActive");
                $("#alterPhoneNo-btn").addClass("notActive");
            }else{
                $.ajax({
                    url:interfaceJudgeTelNo+generateMixed(9),
                    type:'post',
                    data:{mobile:tel},
                    success:function (data) {
                        // console.log(data);
                        if(data.status==0){     // 手机号码可用
                            mobileTOF=true;
                            $(".notActive").removeClass("notActive");
                            /*获取短信验证码，xx秒后重发*/
                            var  code=true;
                            $("#verifyCodeSend-div").on("tap",function () {
                                var SMScode=$("#studentTel").val();
                                if(code){
                                    $.ajax({
                                        url:interfaceSMSAuthenticationCode+generateMixed(9),
                                        type:'post',
                                        data:{mobile:SMScode},
                                        success:function (data) {
                                            if(data.satus){
                                                alert(data.msg);
                                                return false;
                                            }else{
                                                alert(data.msg);
                                                return false;
                                            }
                                        }
                                    });
                                    var number=60;      //60秒后重发
                                    code=false;
                                    $("#verifyCodeSend-div").text(number+'s'+"后可重发");
                                    var timer=setInterval(function () {
                                        number--;
                                        $("#verifyCodeSend-div").text(number+'s'+"后可重发");
                                        if(number<=0){
                                            clearInterval(timer);
                                            code=true;
                                            $("#verifyCodeSend-div").text("获取验证码");
                                        }
                                    },1000);
                                }
                            });
                        }else if(data.status==1){
                            mobileTOF=false;
                            code=false;
                            $("#verifyCodeSend-div").addClass("notActive");
                            $("#alterPhoneNo-btn").addClass("notActive");
                            $(".register-tip").eq(0).html(data.msg);
                        }
                    }
                })
            }
        }
    });
    /*修改手机号提交*/
    $("#alterPhoneNo-btn").on("tap",function () {
        var tel=$("#studentTel").val();
        var code=$("#verificationCode").val();
        if(tel!=''&&code!='') {
            console.log(mobileTOF);
            if(mobileTOF) {
                $.ajax({
                    url: interfaceModifyPersonMsg,
                    type: 'post',
                    data: {type: 'mobile', msg: tel, verifyNum: code},
                    success: function (data) {
                        // console.log(data);
                        if (data.status == 0) {
                            alert(data.msg);
                            return false;
                            window.location.href="/f/campusinfo/personMsg1"+generateMixed(9);
                        } else {
                            alert(data.msg);
                            return false
                        }
                    }
                })
            }else {
                alert("请检查填写的手机号");
                return false
            }
        }else {
            alert("请完善修改信息");
            return false
        }
    })
    /*input、select聚焦时，提示清空*/
    $("#studentTel").focus(function () {
        $(".tip").eq(0).html("");
        $(".register-tip").html("");
    });
</script>
</body>
</html>